<template>
  <div>
    <nav>
      <div class="topbar">
        <div class="imgbox">
          <img src="../assets/搜索.png" alt="" />
        </div>
        <div class="inpbox">
          <input type="text" 
          name="" id="" placeholder="惊涛骇浪" 
          v-model="searchmsg" 
          @keydown.enter="getsearchdata(searchmsg)">
        </div>
        <div class="closebox">
          <router-link :to="{ path: '/' }">
            <button>取消</button>
          </router-link>
        </div>
      </div>
    </nav>
    <section v-if="false">
      <div class="register">热门搜索</div>
      <ul class="reg-list">
        <a href="">
          <div class="numbox"><span>1</span></div>
          <li><span>重返2000</span></li>
        </a>
        <a href="">
          <div class="numbox"><span>1</span></div>
          <li><span>重返2000</span></li>
        </a>
        <a href="">
          <div class="numbox"><span>1</span></div>
          <li><span>重返2000</span></li>
        </a>
        <a href="">
          <div class="numbox"><span>1</span></div>
          <li><span>重返2000</span></li>
        </a>
        <a href="">
          <div class="numbox"><span>1</span></div>
          <li><span>重返2000</span></li>
        </a>
        <a href="">
          <div class="numbox"><span>1</span></div>
          <li><span>重返2000</span></li>
        </a>
      </ul>
      <div class="search-his">
        <div class="search-top">
          <div class="search-tit">最近搜索</div>
          <div class="search-img">
            <button class="clear-btn">
              <img src="../assets/remove-icon.png" alt="" />
            </button>
          </div>
        </div>
        <div class="history-box">
          <ul class="history-list">
            <a href="">
              <div class="imgbox"><img src="../assets/搜索.png" alt="" /></div>
              <li>重返2000</li>
            </a>
            <a href="">
              <div class="imgbox"><img src="../assets/搜索.png" alt="" /></div>
              <li>重返2000</li>
            </a>
            <a href="">
              <div class="imgbox"><img src="../assets/搜索.png" alt="" /></div>
              <li>重返2000</li>
            </a>
            <a href="">
              <div class="imgbox"><img src="../assets/搜索.png" alt="" /></div>
              <li>重返2000</li>
            </a>
            <a href="">
              <div class="imgbox"><img src="../assets/搜索.png" alt="" /></div>
              <li>重返2000</li>
            </a>
            <a href="">
              <div class="imgbox"><img src="../assets/搜索.png" alt="" /></div>
              <li>重返2000</li>
            </a>
          </ul>
        </div>
      </div>
    </section>
    <div class="hotweek">
      <router-link
        v-for="item in searcharr"
        :key="item.id"
        :to="{ path: '/readview', query: { id: item.id } }"
      >
        <div class="mainbox">
          <div class="imgbox">
            <img :src="item.cover" alt="" />
          </div>
          <div class="tuijianeirong">
            <h3>{{ item.text }}</h3>
            <div class="fengge">{{ item.author }}</div>
            <div class="jianjie">
              {{ item.d }}
            </div>
          </div>
        </div>
      </router-link>
    </div>
  </div>
</template>


<script>
import { get } from "../http/request";
export default {
  name: "mysearch",
  data() {
    return {
      searcharr:"",
      searchmsg:"",
    };
  },
  methods: {
    async getsearchdata(books) {
      await get(
        `https://apis.netstart.cn/yunyuedu/search/searchHint?search=${books}`
      ).then((res) => {
        console.log(res.words.w);
        this.searcharr = res.words.w;
        console.log(this.searcharr);
      });
    },
    
  },
  created() {
    // this.getsearchdata();
    // console.log(this.searchmsg);
  },
};
</script>

<style scoped lang="scss">
* {
  padding: 0;
  margin: 0;
  font-size: 16px;
}
a {
  text-decoration: none;
  color: black;
}
nav {
  padding: 0;
  width: 100%;
  height: 50px;
  background-color: #fafafa;
  .topbar {
    width: 100%;
    height: 50px;
    display: flex;
    position: relative;
    .imgbox {
      width: 30px;
      height: 30px;
      position: absolute;
      left: 25px;
      top: 10px;
      img {
        width: 30px;
        height: 30px;
      }
    }
    .inpbox {
      width: 260px;
      height: 40px;
      margin-left: 20px;
      margin-top: 5px;
      input {
        width: 260px;
        height: 40px;
        border: transparent;
        background-color: rgb(239, 236, 236);
        border-radius: 20px;
        padding-left: 40px;
      }
    }
    .closebox {
      width: 50px;
      height: 50px;
      position: absolute;
      right: 10px;
      color: rgb(191, 186, 186);
      button {
        width: 50px;
        height: 50px;
        background-color: transparent;
        border: transparent;
      }
    }
  }
}

section {
  width: 100%;
  margin: 50px 0;
  padding: 0 10px;
  box-sizing: border-box;
  .reg-list {
    box-sizing: border-box;
    width: 100%;
    height: 250px;
    // border: 1px solid black;
    padding: 20px 20px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    a {
      display: block;
      width: 130px;
      height: 30px;
      // border: 1px solid black;
      display: flex;
      align-items: center;
      .numbox {
        width: 20px;
        height: 20px;
        background-color: red;
        color: #fff;
        text-align: center;
        border-radius: 50px;
        margin-right: 10px;
      }
      li {
        display: block;
        width: 100px;
        height: auto;
        display: -webkit-box;
        overflow: hidden; /*超出隐藏*/
        text-overflow: ellipsis; /*隐藏后添加省略号*/
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 1; //想显示多少行
      }
    }
  }
  .search-his {
    width: 100%;
    .search-top {
      width: 100%;
      display: flex;
      justify-content: space-between;
      .search-img {
        width: 30px;
        height: 30px;
        .clear-btn {
          border: transparent;
          background-color: transparent;
          img {
            width: 30px;
            height: 30px;
          }
        }
      }
    }
    .history-box {
      width: 100%;
      .history-list {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        a {
          background-color: gainsboro;
          border-radius: 20px;
          display: flex;
          flex-wrap: nowrap;
          padding: 5px;
          margin-top: 10px;
          .imgbox {
            width: 20px;
            height: 20px;
            img {
              width: 20px;
              height: 20px;
            }
          }
        }
      }
    }
  }
}

.hotweek {
    margin-top: 20px;
  font-size: 16px;
  width: 100%;
  padding: 0 10px;
  box-sizing: border-box;
  a {
    display: block;
    width: 100%;
    height: 180px;
    text-decoration: none;
    color: black;
    .mainbox {
      width: 100%;
      height: 180px;
      display: flex;
      .imgbox {
        width: 100px;
        height: 150px;
        margin: 10px;
        img {
          width: 100px;
          height: 150px;
        }
      }
      .tuijianeirong {
        width: 220px;
        height: 180px;
        display: flex;
        flex-direction: column;
        justify-content: space-around;

        .jianjie {
          width: 220px;
          height: auto;
          display: -webkit-box;
          overflow: hidden; /*超出隐藏*/
          text-overflow: ellipsis; /*隐藏后添加省略号*/
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 3; //想显示多少行
        }
      }
    }
  }
}
</style>